/*Copyright 2014 Douglas Soares

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */
package br.ds.twitter4a.rest;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.ResponseHandlerInterface;

/**
 * Abstract class for requests to twitter.
 */
public abstract class AbstractTwitterRequest {

    /**
     * The base URL.
     */
    protected static final String BASE_URL = "https://api.twitter.com";

    /**
     * The Request Params to perform request.
     */
    protected final RequestParams params = new RequestParams();

    /**
     * The Async Http Client to perform the rest requests.
     */
    private static final AsyncHttpClient CLIENT = new AsyncHttpClient();

    /**
     * Does a get rest request.
     * 
     * @param handler
     */
    public void get(final ResponseHandlerInterface handler) {
	CLIENT.get(getUrl(), params, handler);
    }

    /**
     * Does a post rest request.
     * 
     * @param handler
     */
    public void post(final ResponseHandlerInterface handler) {
	CLIENT.post(getUrl(), params, handler);
    }

    /**
     * Add a new value to the params given a key.
     * 
     * @param key
     *            The key to put on params.
     * @param value
     *            the value to put on params.
     */
    public void addParameter(final String key, final String value) {
	params.add(key, value);
    }

    /**
     * @param responseHandler
     *            the handler for the rest response.
     */
    public abstract void execute(AsyncHttpResponseHandler responseHandler);

    /**
     * @return The url to the specific request.
     */
    public abstract String getUrl();

}
